package com.scott.classicthreadmodal.demo1;

import com.scott.classicthreadmodal.demo1.consumer.Consumer;
import com.scott.classicthreadmodal.demo1.producer.Producer;
import com.scott.classicthreadmodal.demo1.storage.Storage;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ProducerConsumerMain {

    public static void main(String[] args) {
        Storage storage = new Storage();

        System.out.printf("仓库库存：%s\n",storage.getTotal());

        ExecutorService service = Executors.newCachedThreadPool();

        Producer p1 = new Producer("张三",storage);
        Producer p2 = new Producer("李四",storage);

        Consumer c1 = new Consumer("王五",storage);
        Consumer c2 = new Consumer("刘二", storage);

        service.submit(p1);
        service.submit(p2);

        service.submit(c1);
        service.submit(c2);
    }
}
